package org.springperu.aop.demo.service.impl;

import java.util.Date;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springperu.aop.demo.dao.AuditDao;
import org.springperu.aop.demo.dao.CustomerDao;
import org.springperu.aop.demo.model.Audit;
import org.springperu.aop.demo.model.Customer;
import org.springperu.aop.demo.service.CustomerService;

@Service("customerService")
@Transactional(readOnly=true)
public class CustomerServiceImpl implements CustomerService{
	@Autowired
	CustomerDao customerDAO;
	
	@Autowired
	AuditDao auditDAO;
	
	public Customer getCustomer(Customer customer) {
		return customerDAO.getCustomer(customer);
	}
	
	@Transactional(readOnly=false)
	public void saveCustomer(Customer customer) {
		//1)Graba un cliente
		customerDAO.saveCustomer(customer);
		
		//2)Graba en tabla de auditoria
		/*
		Audit audit = new Audit();
		audit.setOperation("INSERT");
		audit.setQuery(customer.toString());
		audit.setAudit_date(new Date());
		audit.setUser_id(1L);
		auditDAO.saveAudit(audit);
		*/
	}

	public List getAllCustomers() {
		return customerDAO.getAllCustomers();
	}
}
